<?php
class word
{
    function start()
    {
        ob_start();
        echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
">';
        //xmlns="http://www.w3.org/TR/REC-html40
    }
    function save($path)
    {

        echo "</html>";
        $data = ob_get_contents();
        ob_end_clean();



        $this->wirtefile ($path,$data);
    }

    function wirtefile ($fn,$data)
    {
        $fp=fopen($fn,"wb");
        fwrite($fp,$data);
        fclose($fp);
    }
}

$data=$_POST['data'];
$arrData=json_decode($data,true);


$html = '
<table width=600 cellpadding="6" cellspacing="1" bgcolor="#eee">
<tr >
 <td bgcolor="gray"><b>会员卡号</b></td>
 <td bgcolor="gray"><b>时间</b></td>
 <td bgcolor="gray"><b>姓名</b></td>
 <td bgcolor="gray"><b>渠道</b></td>
 <td bgcolor="gray"><b>项目</b></td>
 <td bgcolor="gray"><b>治疗人员</b></td>
 <td bgcolor="gray"><b>设备</b></td>
 <td bgcolor="gray"><b>时长</b></td>
 <td bgcolor="gray"><b>备注</b></td>
 <td bgcolor="gray"><b>邀约</b></td>
</tr>
';
foreach($arrData['datas'] as $key=>$value){
    if($value['doctor']!="{'空'}")$doctor=$value['doctor'];
    if($value['meirongshi']!="{'空'}")$doctor.=$value['meirongshi'];

    $html.="<tr>
     <td>{$value['hongmai']}</td>
     <td bgcolor='#dddddd'>{$value['shijian']}</td>
     <td>{$value['name']}</td>
     <td bgcolor='#dddddd'>{$value['from']}</td>
     <td>{$value['buwei']}</td>
     <td bgcolor='#dddddd'>{$doctor}</td>
     <td>{$value['shebei']}</td>
     <td bgcolor='#dddddd'>{$value['spendtime']}</td>
     <td>{$value['content']}</td>
     <td bgcolor='#dddddd'>{$value['yaoyue']}</td>
    </tr>";
}
$html.='</table>';



//批量生成 
//for($i=1;$i<=3;$i++){
$word = new word();
$word->start();
//$html = "aaa".$i;
$wordname ="./data/".$arrData['fileName'];
echo $html;
$word->save($wordname);
ob_flush();//每次执行前刷新缓存
flush();
//}
